package com.bang.sgg.controller;

import com.bang.sgg.persist.model.AgentSeat;
import com.bang.sgg.persist.model.constant.QueueConstant;
import com.bang.sgg.service.MessageService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @Auther: Bang
 * @Date: 2019/11/23 11:47
 * @Description:
 */
@RestController
public class TestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private MessageService messageService;

    @GetMapping("/topic")
    public Object test1() {
        AgentSeat agentSeat = new AgentSeat();
        agentSeat.setId(1L);
        agentSeat.setExtCode("10086");
        agentSeat.setSeatCode("10086");
        agentSeat.setExtPass("123456");
        agentSeat.setUpdateTime(new Date());
//        rabbitTemplate.convertAndSend(QueueConstant.AGENT_TOPIC_EXCHANGE,QueueConstant.AGENT_ROUTE_KEY,agentSeat);
        String id = UUID.randomUUID().toString();
        messageService.send(QueueConstant.AGENT_TOPIC_EXCHANGE,QueueConstant.AGENT_ROUTE_KEY,agentSeat,new CorrelationData(id));
        return id;
    }

    @GetMapping("/fanout")
    public Object fanout() {
        AgentSeat agentSeat = new AgentSeat();
        agentSeat.setId(1L);
        agentSeat.setExtCode("10086");
        agentSeat.setSeatCode("10086");
        agentSeat.setExtPass("123456");
        agentSeat.setUpdateTime(new Date());
        rabbitTemplate.convertAndSend(QueueConstant.FANOUT_EXCHANGE,null,agentSeat);
        return "SUCCESS";
    }
}
